package com.android.love.adapter;

import java.util.Collections;
import java.util.List;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.love.R;
import com.android.love.util.ImageUtils;
import com.android.love.view.GridViewWithHeaderBaseAdapter;
import com.android.love.vo.Goods;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;

public class CommentAdapter_1 extends GridViewWithHeaderBaseAdapter {

	private static final String TAG = "CommentAdapter";
	private ImageLoader loader;
	private List<Goods> goods = Collections.emptyList();;
	private Context context;
	private int arrange_type;

	public CommentAdapter_1(Context context, ImageLoader loader,
			List<Goods> goods, int arrange_type) {
		super(context);
		this.context = context;
		this.loader = loader;
		this.goods = goods;
		this.arrange_type = arrange_type;
	}

	public void setArrangeType(int arrange_type) {
		this.arrange_type = arrange_type;
	}

	// @Override
	// public int getCount() {
	// // TODO Auto-generated method stub
	// return goods.size();
	// }

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return goods.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	// @Override
	// public View getView(int position, View convertView, ViewGroup parent) {
	// ViewHolder holder;
	// if (convertView == null) {
	// if (arrange_type == 0)
	// convertView = View.inflate(context, R.layout.grid_item, null);
	// else
	// convertView = View.inflate(context, R.layout.detai_item, null);
	// holder = new ViewHolder();
	// holder.iv_comment_img = (ImageView) convertView
	// .findViewById(R.id.iv_comment_img);
	// holder.tv_comment_title = (TextView) convertView
	// .findViewById(R.id.tv_comment_title);
	// holder.tv_comment_price = (TextView) convertView
	// .findViewById(R.id.tv_comment_price);
	// holder.tv_comment_old_price = (TextView) convertView
	// .findViewById(R.id.tv_comment_old_price);
	// convertView.setTag(holder);
	// } else {
	// holder = (ViewHolder) convertView.getTag();
	// }
	// // Goods good = new Goods();
	// Goods good = goods.get(position);
	// holder.tv_comment_title.setText(good.getGoods_name());
	// holder.tv_comment_price.setText("￥" + good.getPrice() + "");
	// holder.tv_comment_price.getPaint().setFlags(
	// Paint.FAKE_BOLD_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
	// holder.tv_comment_old_price.setText("￥" + good.getOld_price() + "");
	// holder.tv_comment_old_price.getPaint().setFlags(
	// Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
	// // loader.displayImage(good.getGoods_image(), holder.iv_comment_img,
	// // options, animateFirstListener);
	// if (arrange_type == 0)
	// loader.displayImageForSize(good.getGoods_image(),
	// holder.iv_comment_img,
	// ImageUtils.getOptions(R.drawable.zwt1),
	// new SimpleImageLoadingListener(), 0, 0, 0, 0, 0, 0, 2f,
	// true);
	// else
	// loader.displayImageForSize(good.getGoods_image(),
	// holder.iv_comment_img,
	// ImageUtils.getOptions(R.drawable.zwt2),
	// new SimpleImageLoadingListener(), 10, 10, 10, 10, 0, 0, 4f,
	// true);
	// return convertView;
	// }

	public static class ViewHolder {
		TextView tv_comment_title;
		ImageView iv_comment_img;
		TextView tv_comment_price;
		TextView tv_comment_old_price;
	}

	@Override
	public int getItemCount() {
		// TODO Auto-generated method stub
		return goods.size();
	}

	@Override
	protected View getItemView(int position, View view, ViewGroup parent) {
		ViewHolder holder;
		if (view == null) {
			if (arrange_type == 0)
				view = View.inflate(context, R.layout.grid_item, null);
			else
				view = View.inflate(context, R.layout.detai_item, null);
			holder = new ViewHolder();
			holder.iv_comment_img = (ImageView) view
					.findViewById(R.id.iv_comment_img);
			holder.tv_comment_title = (TextView) view
					.findViewById(R.id.tv_comment_title);
			holder.tv_comment_price = (TextView) view
					.findViewById(R.id.tv_comment_price);
			holder.tv_comment_old_price = (TextView) view
					.findViewById(R.id.tv_comment_old_price);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		// Goods good = new Goods();
		Goods good = goods.get(position);
		holder.tv_comment_title.setText(good.getGoods_name());
		holder.tv_comment_price.setText("￥" + good.getPrice() + "");
		holder.tv_comment_price.getPaint().setFlags(
				Paint.FAKE_BOLD_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
		holder.tv_comment_old_price.setText("￥" + good.getOld_price() + "");
		holder.tv_comment_old_price.getPaint().setFlags(
				Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
		// loader.displayImage(good.getGoods_image(), holder.iv_comment_img,
		// options, animateFirstListener);
		if (arrange_type == 0)
			loader.displayImageForSize(good.getGoods_image(),
					holder.iv_comment_img,
					ImageUtils.getOptions(R.drawable.zw4),
					new SimpleImageLoadingListener(), 0, 0, 0, 0, 0, 0, 2f,
					true);
		else
			loader.displayImageForSize(good.getGoods_image(),
					holder.iv_comment_img,
					ImageUtils.getOptions(R.drawable.zw2),
					new SimpleImageLoadingListener(), 5, 5, 5, 5, 0, 0, 4f,
					true);
		return view;

	}

}
